﻿@inject Microsoft.CST.AttackSurfaceAnalyzer.Cli.AppData appData

<div>
    <div class="form-group">
        <div class="form-check">
            <input type="checkbox" class="form-check-input" id="enableRegistryCollectionCheckbox" @bind="appData.CollectOptions.EnableRegistryCollector" />
            <label class="form-check-label" for="enableRegistryCollectionCheckbox">Enable Registry Collector</label>
        </div>
    </div>
    <div class="form-group">
        <label for="selectedPathsString">Add Path to Scan:</label>
        <div class="form-row">
            <div class="col-9 mb-1">
                <input type="text" class="form-control" id="selectedPathsString" placeholder="LocalMachine\\SOFTWARE\Microsoft" @bind="SelectedHiveInput" />
            </div>
            <div class="col">
                <button class="btn btn-secondary" @onclick="PushInputToList">Add</button>
            </div>
        </div>
    </div>
    <div class="form-group">
        <label for="selectedPathsList">Selected Paths:</label>
        <div class="form-row">
            <div class="col-9 mb-1">
                <select class="form-control @directorySelectElementGlowClass.ClassName" id="selectedPathsList" @bind="SelectedHiveTop">
                    @for (var i = 0; i < appData.CollectOptions.SelectedHives.Count(); i++)
                    {
                        <option value="@i">@appData.CollectOptions.SelectedHives.ToList()[i]</option>
                    }
                </select>
            </div>
            <div class="col">
                <button class="btn btn-secondary" @onclick="RemoveInputFromList">Remove</button>
            </div>
        </div>
    </div>
</div>

@code{
    Helper.GlowClass directorySelectElementGlowClass = new Helper.GlowClass();

    string SelectedHiveInput = string.Empty;
    int SelectedHiveTop;

    void RemoveInputFromList()
    {
        appData.CollectOptions.SelectedHives = appData.CollectOptions.SelectedDirectories.Except(appData.CollectOptions.SelectedDirectories.Skip(SelectedHiveTop-1).Take(1));
        Helper.ToggleGlow(() => InvokeAsync(StateHasChanged), directorySelectElementGlowClass, false);
    }

    void PushInputToList()
    {
        appData.CollectOptions.SelectedHives = appData.CollectOptions.SelectedHives.Union(new string[] { SelectedHiveInput });
        SelectedHiveTop = appData.CollectOptions.SelectedHives.Count() - 1;
        Helper.ToggleGlow(() => InvokeAsync(StateHasChanged), directorySelectElementGlowClass, true);
        SelectedHiveInput = string.Empty;
    }
}
